<template>
  <el-form :inline="true" :model="RidegShows" class="demo-form-inline">
    <el-form-item label="栋舍名称">
      <el-input v-model="RidegShows.sheepFullName" clearable />
    </el-form-item>

    <el-form-item label="负责人">
      <el-input v-model="RidegShows.responsiblePerson" clearable />
    </el-form-item>

    <el-form-item>
      <el-button type="primary" @click="GetEagList">查询</el-button>
      <el-button type="primary" @click="Addinfo">添加</el-button>
      <el-button type="danger" @click="DeleteRanges">批量删除</el-button>
    </el-form-item>
  </el-form>
  <el-table :data="tableData" border style="width: 100%" @selection-change="handleSelectionChange">
    <el-table-column type="selection" width="55" />
    <el-table-column prop="ridgepoleId" label="序号" />
    <el-table-column prop="ridgepoleTypeId" label="栋舍类型" v-slot="scope">
      <span v-if="scope.row.ridgepoleTypeId == 1">公羊舍</span>
      <span v-if="scope.row.ridgepoleTypeId == 2">配种舍</span>
      <span v-if="scope.row.ridgepoleTypeId == 3">妊娠舍</span>
      <span v-if="scope.row.ridgepoleTypeId == 4">分娩舍</span>
      <span v-if="scope.row.ridgepoleTypeId == 5">青年舍</span>
      <span v-if="scope.row.ridgepoleTypeId == 6">育肥舍</span>
      <span v-if="scope.row.ridgepoleTypeId == 7">隔离舍</span>
      <span v-if="scope.row.ridgepoleTypeId == 8">混合舍</span>
      <span v-if="scope.row.ridgepoleTypeId == 9">哺乳舍</span>
      <span v-if="scope.row.ridgepoleTypeId == 10">后备舍</span>
    </el-table-column>
    <el-table-column prop="ridgepoleName" label="栋舍名称" />
    <el-table-column prop="responsiblePerson" label="负责人" />
    <el-table-column prop="productionPersonnel" label="生产人员" />
    <el-table-column prop="remark" label="备注" />
    <el-table-column prop="createName" label="创建人" />
    <el-table-column prop="createTime" label="创建时间" />



    <el-table-column prop="" label="栏位管理" width="180" v-slot="scope">

      <el-button type="danger" @click="Column(scope.row.ridgepoleId)">栏位管理</el-button>

    </el-table-column>
    <el-table-column prop="" label="操作" width="180" v-slot="scope">
      <el-button type="danger" @click="deletes(scope.row.ridgepoleId)">删除</el-button>
      <el-button type="danger" @click="Updates(scope.row.ridgepoleId)">修改</el-button>

    </el-table-column>
  </el-table>
  <table>
    <tr>
      <!-- <td>
        <el-pagination v-model:current-page="startQuery.PageIndex" v-model:page-size="startQuery.PageSize"
          :page-sizes="[3, 7, 10, 20]" :size="size" :disabled="disabled" :background="background"
          layout="total, sizes, prev, pager, next, jumper" :total="page.total" @size-change="handleSizeChange"
          @current-change="handleCurrentChange" />
      </td> -->
      <td>
        <el-pagination v-model:current-page="RidegShows.PageIndex" v-model:page-size="RidegShows.PageSize"
          :page-sizes="[3, 7, 10, 20]" :size="size" :disabled="disabled" :background="background" layout="slot"
          :total="page.total" @size-change="handleSizeChange" @current-change="handleCurrentChange">
          <span>
            当前{{ RidegShows.PageIndex }}/{{ page.totalPage }},共{{
            page.total
            }}条数据
          </span>
        </el-pagination>
      </td>
      <td>
        <el-pagination v-model:current-page="RidegShows.PageIndex" v-model:page-size="RidegShows.PageSize"
          :page-sizes="[3, 7, 10, 20]" :size="size" :disabled="disabled" :background="background" prev-text="上一页"
          next-text="下一页" layout="sizes,slot, prev, pager, next" :total="page.total" @size-change="handleSizeChange"
          @current-change="handleCurrentChange">
          <el-button type="primary" @click="handleCurrentChange(1)">
            首页
          </el-button>
        </el-pagination>
      </td>

      <td>
        <el-pagination v-model:current-page="RidegShows.PageIndex" v-model:page-size="RidegShows.PageSize"
          :page-sizes="[3, 7, 10, 20]" :size="size" :disabled="disabled" :background="background" prev-text="上一页"
          next-text="下一页" layout="slot, jumper" :total="page.total" @size-change="handleSizeChange"
          @current-change="handleCurrentChange">
          <el-button type="primary" @click="handleCurrentChange(page.totalPage)">
            尾页
          </el-button>
        </el-pagination>
      </td>
    </tr>
  </table>


</template>

<script lang="ts" setup>
import starts from "@/api/EarTagManagement/index";
import vendor from "@/api/OrganizationalAdministration/index";
import { Ridgepole } from "@/api/OrganizationalAdministration/model";
import { Rideg } from "@/api/OrganizationalAdministration/index";
import axios from "axios";
import { number } from "echarts";

import { useRouter, useRoute } from 'vue-router';
const UseRous = useRouter()
const useRoutea = useRoute()


const Updates = (ridgepoleId) => {
  UseRous.push({
    path:"/ridgepoleUpdate",
    query: {
      ridgepoleId: ridgepoleId
    }
  })
}
const handleSizeChange = (val: number) => {
  RidegShows.PageSize = val;
  RidegShows.PageIndex = 1;
  GetEagList();
};
const handleCurrentChange = (val: number) => {
  RidegShows.PageIndex = val;
  GetEagList();
};

const Column = (ridgepoleId) => {
  UseRous.push({
    path: "/ColumnListShow",
    query:{
      ridgepoleId: ridgepoleId
    }
  })
}

// const Ridgepoles = reactive<Ridgepole>({
//   RidgepoleTypeId: 0,
//   RidgepoleName: "",
//   ResponsiblePerson: "",
//   PageIndex: 1,
//   PageSize: 5
// });

const RidegShows = reactive<Rideg>({
  PageIndex: 1,
  PageSize: 20,
  sheepId: null,
  sheepFullName: "",
  responsiblePerson: ""
})






const page = reactive({
  total: 0,
  totalPage: 0,
});

const Addinfo = () => {
  UseRous.push("/ridgepoleAdd")
}

const Checkeds = ref();
const ids = ref([])
const handleSelectionChange = (val: []) => {
  Checkeds.value = val;
  Checkeds.value.forEach(item => {
    ids.value.push(item.ridgepoleId)
  })
};


const DeleteRanges = () => {
  if (ids.value.length == 0) {
    ElMessage({
      message: '请选择要删除的数据',
      type: 'warning',
    })
    return
  }
  ElMessageBox.confirm(
    '您确定要删除吗',
    'Warning',
    {
      confirmButtonText: '确定',
      cancelButtonText: '取消',
      type: 'warning',
    }
  )
    .then(() => {
      vendor.DeleteRan(ids.value).then((res: any) => {
        if (res.data > 0) {
          ElMessage.success("删除成功");
          GetEagList();
        }
        else {
          ElMessage.error("删除失败");
        }
      })
    })
    .catch(() => {
      ElMessage({
        type: 'info',
        message: 'Delete canceled',
      })
    })

};






const deletes = (id: number) => {
  vendor.deleteridgepoles(id)
    .then((res: any) => {
      ElMessageBox.confirm("您确定要删除吗", "Warning", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      }).then(() => {
        if (res.data > 0) {
          ElMessage.success("删除成功");
          GetEagList();
        } else {
          ElMessage.error("删除失败");
        }
      });
    })
    .catch(() => {
      ElMessage({
        type: "info",
        message: "Delete canceled",
      });
    });
};



const tableData: any = ref([]);

const GetEagList = () => {
  vendor.getList(RidegShows).then((res: any) => {
    console.log("数据", res.data.total);
    console.log("数据", res.data.totalPage);
    (tableData.value = res.data.data),
      (page.total = res.data.total),
      (page.totalPage = res.data.totalPage);
  });
};

onMounted(() => {
  GetEagList();
});
</script>
